using DG.Tweening;
using UnityEngine;
using UnityEngine.EventSystems;

public class UIHoverScaleTween : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
    [Header("缩放设置")]
    public float hoverScale = 1.2f;
    public float normalScale = 1f;
    public float duration = 0.3f;
    
    private RectTransform rectTransform;
    private Tween currentTween;

    void Start()
    {
        rectTransform = GetComponent<RectTransform>();
    }

    public void OnPointerEnter(PointerEventData eventData)
    {
        currentTween?.Kill();
        currentTween = rectTransform.DOScale(hoverScale, duration)
            .SetEase(Ease.OutBack)
            .SetUpdate(true); // 不受Time.timeScale影响
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        currentTween?.Kill();
        currentTween = rectTransform.DOScale(normalScale, duration)
            .SetEase(Ease.OutBack)
            .SetUpdate(true);
    }

    void OnDisable()
    {
        // 禁用时重置缩放
        rectTransform.localScale = Vector3.one * normalScale;
    }
}